<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>设备管理</title>
	<link rel="stylesheet" href="../css/common2.css">
<link rel="stylesheet" href="/scriptZIP/layui.min.css">
	<link rel="stylesheet" href="../css/layui.css" />
	<style>
		.add {
			display: inline-block;
		}

		.search {
			margin-top: -20px;
		}

		.school {
			margin-left: 20px;
			margin-top: 20px;
			display: inline-block;
		}

		.search_img {
			position: absolute;
			margin-top: -20px;
			right: 3%;
		}

		.pagination li a {
			padding: 9px 12px !important;
		}
	</style>
</head>

<body class="main-body">

	<div id="vue-root" style="margin-top: 50px;">
		<div class="add action-buttons" v-if="able.add">
			<a href="device3_item.html" style="color: white">添加设备</a>
		</div>
		<div class="refresh action-buttons" onclick="location.reload()">刷新</div>
		<div class="anniu" @click="show_start=true">开关机时间</div>

		<br>

		<div class="table ">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box" v-model="all">序号
						</th>
						<th>设备位置</th>
						<th>设备编码</th>
						<th>刷新数据</th>
						<th>最新请求时间</th>
						<th v-if="able.edit">编辑</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(device,index) in list" :key="device.id">
						<td>
							<input type="checkbox" class="check-box" v-model="device.checked">
							<span v-text="index+1"></span>
						</td>

						<td v-text="device.name"></td>
						<td v-text="device.code"></td>
						<td>
							<button @click="refresh(device.id)">刷新数据</button>
						</td>
						<td v-text="format(device.latestTime)"></td>

						<td v-if="able.edit">
							<div>
								<div class="edit-icon option-icon">
									<a :href="'device3_item.html?id='+device.id">
										<img class="img" height="20" width="20" src="../image/edit.png"
											onmouseover="this.src='../image/edit_light.png'"
											onmouseout="this.src='../image/edit.png'" />
									</a>
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>

		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>

		<div class="home_zz" v-show="show_start">
			<div class="d_time" style="z-index: 11">
				<p style="text-align: center;font-size: 20px">开关机时间设置</p>
				<br /><br />
				<div class="layui-form-item">
					<input name="newsTime" data-vv-as="时间" id="ktime" autocomplete="off" placeholder="请输入开机时间"
						class="time_divs" v-model="ktime">
				</div>
				<div class="layui-form-item">
					<input name="newsTime" data-vv-as="时间" id="jtime" autocomplete="off" placeholder="请输入关机时间"
						class="time_divs" v-model="jtime">
				</div>
				<div style="margin-top: 40px;">
					<input type="button" class="but" value="确认" @click="submit">
					<input type="button" class="but" value="取消" @click="show_start=false">
				</div>
			</div>
		</div>
	</div>


	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>
	<script src="/scriptZIP/qs.min.js"></script>

	<script src="/scriptZIP/dayjs.min.js"></script>

	<script src="/scriptZIP/dayjs.min.js"></script>

	<script src="/lib/laydate/laydate.js"></script>
	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>

		var app = new Vue(merge({
			data: {
				urls: {
					del: '/pc/device/del',
					list: '/pc/device/list'
				},
				search: {
					schoolId: top_params().id,
					type: 2
				},
				show_start: false,
				ktime: null,
				jtime: null,
			},
			created: function () {
				if (!this.search.schoolId)
					return axios.get('/pc/logout').then(function (res) {
						alert('此浏览器不适用本系统，请更换浏览器');
						location.replace('/');
					});
				this.getData();
				abled('device', this);
			},
			methods: {
				format: function (time) {
					if (!time) return '';
					return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
				},
				refresh: function (id) {
					axios.post('/pc/device/refresh/' + id).then(function (res) {
						if (res.data) alert('已发送请求');
						else alert('设备未连接。请检查设备网络连接');
					});
				},
				submit() {
					alert("okk")
				}
			}
		}));
		laydate.render({
			elem: '#ktime', //指定元素
			type: "time",
			done: function (value, date, endDate) {
				this.ktime = value;
			}
		});
		laydate.render({
			elem: '#jtime', //指定元素
			type: "time",
			done: function (value, date, endDate) {
				this.jtime = value;
			}
		});
	</script>
</body>

</html>